<template>
  <div style="text-align: center;">
    <h2>你好！{{ userInfo.username }} 同学</h2>

    <el-form :model="applicantForm" status-icon :rules="rules" ref="passForm" label-width="100px">
      <el-form-item label="姓名" prop="name">
        <el-input v-model="applicantForm.name" clearable></el-input>
      </el-form-item>
      <el-form-item label="身份证号码" prop="identity">
        <el-input v-model="applicantForm.identity" clearable></el-input>
      </el-form-item>
      <el-form-item label="籍贯" prop="nativePlace">
        <el-input v-model="applicantForm.nativePlace" clearable></el-input>
      </el-form-item>
      <el-form-item label="电话" prop="telephone">
        <el-input v-model="applicantForm.telephone" clearable></el-input>
      </el-form-item>
      <el-form-item label="邮政编码" prop="code">
        <el-input v-model="applicantForm.code" clearable></el-input>
      </el-form-item>
      <el-form-item label="地址" prop="address">
        <el-input v-model="applicantForm.address" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm('passForm')">立即绑定</el-button>
        <el-button @click="resetForm('passForm')">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name: "ApplicantBind",
  data() {
    return {

      userInfo: {},
      applicantForm: {
        name: '',
        identity: '',
        nativePlace: '',
        telephone: '',
        code: '',
        address: '',
      },
      rules: {
        name: [
          {required: true, message: '请输入姓名', trigger: 'blur'}
        ],
        identity: [
          {required: true, message: '请输入身份证号码', trigger: 'blur'},
          {min: 18, max: 18, message: '长度在为18个字符', trigger: 'blur'}
        ],
        nativePlace: [
          {required: true, message: '请输入籍贯', trigger: 'blur'}
        ],
        telephone: [
          {required: true, message: '请输入电话号码', trigger: 'blur'},
          {min: 11, max: 11, message: '长度在为11个字符', trigger: 'blur'}
        ],
        code: [
          {required: true, message: '请输入邮政编码', trigger: 'blur'},
          {min: 6, max: 6, message: '长度在为6个字符', trigger: 'blur'}
        ],
        address: [
          {required: true, message: '请输入地址', trigger: 'blur'}
        ],
      },
    }
  },
  created() {
    this.$axios.get("/user/userInfo").then(res => {

      this.userInfo = res.data.data;
    })
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$message({
            message: '恭喜你，绑定成功！',
            type: 'success'
          });

        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  }

}
</script>

<style scoped>
.el-form {
  width: 420px;
  margin: 50px auto;
}
</style>